package com.zdsoft.blp.gongyong.upLoad;

import android.graphics.Bitmap;
import android.util.Base64;

import java.io.ByteArrayOutputStream;

/**
 * Created by pc on 2016/9/10.
 */
public class Base64ToString {
    public static String toString(Bitmap bitmap){
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int quality = 80;
        bitmap.compress(Bitmap.CompressFormat.JPEG,quality,out);
        while(out.toByteArray().length/1024>100){
            out.reset();
            quality -= 10;
            bitmap.compress(Bitmap.CompressFormat.JPEG,quality,out);
        }
        byte[] data = out.toByteArray();

        String base64 = Base64.encodeToString(data,Base64.DEFAULT);
        return base64;
    }
}
